package com.and.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.and.constant.ImageTool;
import com.and.main.R;
import com.and.vo.Friend;

/**
 * 
 * @author 何鑫
 * @param 为ListView适配数据 
 *
 */
public class FriendAdapter extends BaseAdapter {

	private class FriendViewHolder {
		ImageView imgHead;
		TextView info;
	}

	private List<Friend> friendList;
	private LayoutInflater minflater;
	public FriendAdapter(Context con, List<Friend> flist) {
		friendList = flist;
		minflater = (LayoutInflater) con
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	
	@Override
	public int getCount() {
		return this.friendList.size();
	}

	@Override
	public Object getItem(int i) {
		return this.friendList.get(i);
	}

	@Override
	public long getItemId(int i) {
		return i;
	}

	@Override
	public View getView(int i, View view, ViewGroup viewgroup) {
		FriendViewHolder holder;
		if(view == null){
			view = this.minflater.inflate(R.layout.friend, null);
			holder =new FriendViewHolder();
			holder.imgHead = (ImageView)view.findViewById(R.id.imghead);
			holder.info = (TextView)view.findViewById(R.id.info);
			view.setTag(holder);
			
		}else{
			holder = (FriendViewHolder)view.getTag();
		}
		
		Friend friend = this.friendList.get(i);
		if(friend!=null){
			 //holder.imgHead.setImageResource(R.drawable.expert);
			 String imgfile="/res/drawable/expert.png";
			 holder.imgHead.setImageBitmap(new ImageTool().genBitmapByImageFile(imgfile));
			 holder.info.setText(friend.getName()+"\n"+friend.getEmail());
		}
		return view;
	}
	/**
	 * 
	 * @Title: clear
	 * @Description: 清空
	 */
	public void clear(){
		if(friendList!=null){
			this.friendList.clear();
		}
	}
	/**
	 * 
	 * @Title: remove
	 * @Description: 删除
	 * @param position    设定文件
	 */
	public void remove(int position){
		this.friendList.remove(position);
		this.notifyDataSetChanged();
	}
	/*public void setCount(int count){
		this.count = count;
	}*/
	public void initList(List<Friend> friendList){
		this.friendList = friendList;
	}
}
